package 多线程.线程池;

import org.junit.Test;

import java.util.concurrent.*;

/**
 * Description
 *
 * @Author: Heiffeng
 * @Date: 2021/12/16 18:23
 */
public class 线程池测试 {

    final static ThreadPoolExecutor POOL = new ThreadPoolExecutor(
            2,
            4,
            60,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(2),
            Executors.defaultThreadFactory(),
            (thread,pool)->{
                try {
                    System.out.println("Current Pool Size:"+pool.getPoolSize()+",Queue Size:"+pool.getQueue().size());
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

    @Test
    public void ceshi1(){
        while(true){
            POOL.execute(()->{
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("Thread:"+Thread.currentThread().getName());
            });
        }

    }
}
